﻿using Org.BouncyCastle.Utilities.Encoders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SZHelperCore.GMSM
{
    public class SM3Utils
    {
        public static string StrSM3(string str)
        {
            //加密
            byte[] msg = Encoding.Default.GetBytes(str);
            byte[] md = new byte[32];
            SM3Digest sm3 = new SM3Digest();
            sm3.BlockUpdate(msg, 0, msg.Length);
            sm3.DoFinal(md, 0);
            string PasswdDigest = new UTF8Encoding().GetString(Hex.Encode(md));
            return PasswdDigest.ToUpper();
        }
        public static string ByteSM3(byte[] bytes)
        {
            //加密
            byte[] md = new byte[32];
            SM3Digest sm3 = new SM3Digest();
            sm3.BlockUpdate(bytes, 0, bytes.Length);
            sm3.DoFinal(md, 0);
            string PasswdDigest = new UTF8Encoding().GetString(Hex.Encode(md));
            return PasswdDigest.ToUpper();
        }
    }
}
